#ifndef BARCODE_EXCEPT_HPP_INCLUDED
#define BARCODE_EXCEPT_HPP_INCLUDED

#include <stdexcept>

namespace barcode
{

struct barcode_error
	: std::runtime_error
{
	barcode_error( const std::string& message_ )
		: std::runtime_error( message_ )
	{
	}
};

struct invalid_code_length
	: barcode_error
{
	invalid_code_length()
		: barcode_error( "invalid code length" )
	{
	}
};

struct not_a_digit
	: barcode_error
{
	not_a_digit()
		: barcode_error( "not a digit" )
	{
	}
};

template < class ExceptionType >
inline void raise_exception( const ExceptionType& error_ )
{
	throw error_;
}

template < class ExceptionType >
inline void throw_if( bool condition_ )
{
	if ( condition_ )
		raise_exception( ExceptionType() );
}

template < class ExceptionType >
inline void throw_if( bool condition_, const std::string& message_ )
{
	if ( condition_ )
		raise_exception( ExceptionType( message_ ) );
}

}

#endif //BARCODE_EXCEPT_HPP_INCLUDED
